#ifndef _K_STREAM_
#define _K_STREAM_

#include "KMemory.h"

namespace krt
{
		class KRUNTIME_CLASS stream
		{
		public:
			typedef UINT64 size_type;
			typedef INT64 offset_type;

			typedef enum {
				soFromBeginning,
				soFromCurrent,
				soFromEnd
			} SeekOrigin;
	
			size_type GetPosition();
			void SetPosition(size_type NewPos);
			void SetSize(size_type NewSize);

			virtual size_type GetSize();
			virtual void SetEnd() = 0;
			virtual size_type seek(offset_type offset, SeekOrigin origin) = 0;
			virtual size_t read(void* buf, size_t BufSize) = 0;
			virtual size_t write(const void* buf, size_t BufSize) = 0;
		};

		class KRUNTIME_CLASS MemoryStream: public stream
		{
		public:
			MemoryStream(const MemoryManager* mm): m_MemMgr(mm), m_buf(NULL), m_capacity(0), m_size(0){}
			~MemoryStream();

			virtual void SetEnd() = 0;
			virtual size_type seek(offset_type offset, SeekOrigin origin) = 0;
			virtual size_t read(void* buf, size_t BufSize) = 0;
			virtual size_t write(const void* buf, size_t BufSize) = 0;

		private:
			const MemoryManager *m_MemMgr;
			char *m_buf;
			size_type m_capacity;
			size_type m_size;
			size_type m_pos;
			MemoryStream(const MemoryStream&);
			MemoryStream& operator=(const MemoryStream&);
		};
}

#endif	//_K_STREAM_